import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '@/views/pageHome/index.vue'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import {getToken, setToken} from "@/utils/auth";
import {setTitle} from "@/utils/tools";
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/index',
    name: 'Home',
    component: Home,
    children: [
      {
        path: 'index',
        name: '首页',
        component: () => import(/* webpackChunkName: "about" */ '@/views/pageHome/productList.vue')
      },
      {
        path: 'productListGeneral',
        name: '服务产品通用券',
        component: () => import(/* webpackChunkName: "about" */ '@/views/pageHome/productListGeneral.vue')
      },
      {
        path: 'productListSpecial',
        name: '服务产品专项券',
        component: () => import(/* webpackChunkName: "about" */ '@/views/pageHome/productListSpecial.vue')
      },
      {
        path: 'productDetail',
        name: '产品详情',
        component: () => import(/* webpackChunkName: "about" */ '@/views/pageHome/productDetail.vue')
      },
      {
        path: 'submitOrder',
        name: '申请服务',
        component: () => import(/* webpackChunkName: "about" */ '@/views/pageContent/orderManage/submitOrder.vue')
      },
      {
        path: 'serviceCompany',
        name: '服务商',
        component: () => import(/* webpackChunkName: "about" */ '@/views/pageContent/serviceCompany/index.vue')
      },
      {
        path: 'companyDetail',
        name: '服务商详情',
        component: () => import(/* webpackChunkName: "about" */ '@/views/pageContent/serviceCompany/companyDetail.vue')
      },
      {
        path: 'requirementList',
        name: '企业需求列表',
        component: () => import(/* webpackChunkName: "about" */ '@/views/pageContent/requirementManage/requirementList.vue')
      },
      {
        path: 'personalCenter',
        component: () => import(/* webpackChunkName: "about" */ '@/views/pageContent/personalCenter/index.vue'),
        children:[
          {
            path: '', // 默认子路由
            redirect: 'profile', // 重定向到个人资料页面
            component: () => import(/* webpackChunkName: "about" */ '@/views/pageContent/personalCenter/profile.vue'),
          },
          {
            path: 'profile',
            name: '个人中心',
            component: () => import('@/views/pageContent/personalCenter/profile.vue'),
          },
          {
            path: 'couponApply',
            name: '服务券配额申请',
            component: () => import(/* webpackChunkName: "about" */ '@/views/pageContent/couponManage/components/couponApply.vue')
          },
          {
            path: 'serviceCompanyApply',
            name: '申请入驻平台',
            component: () => import(/* webpackChunkName: "about" */ '@/views/pageContent/couponManage/components/serviceCompanyApply.vue')
          },
          {
            path: 'couponOrder',
            name: '我购买的服务',
            component: () => import(/* webpackChunkName: "about" */ '@/views/pageContent/orderManage/couponOrder.vue')
          },
          {
            path: 'couponOrderDetail',
            name: '我购买的服务订单详情',
            component: () => import(/* webpackChunkName: "about" */ '@/views/pageContent/orderManage/couponOrderDetail.vue')
          },
          {
            path: 'productOrder',
            name: '我的服务订单',
            component: () => import(/* webpackChunkName: "about" */ '@/views/pageContent/orderManage/productOrder.vue')
          },
          {
            path: 'productOrderDetail',
            name: '我的服务产品订单详情',
            component: () => import(/* webpackChunkName: "about" */ '@/views/pageContent/orderManage/productOrderDetail.vue')
          },
          {
            path: 'serviceCompanyInfo',
            name: '服务商信息',
            component: () => import(/* webpackChunkName: "about" */ '@/views/pageContent/serviceCompanyManage/component/serviceCompanyComp.vue')
          },
          {
             path: 'serviceProductManage',
             name: '服务产品管理',
             component: () => import(/* webpackChunkName: "about" */ '@/views/pageContent/serviceCompanyManage/serviceProductManage.vue')
           },
          {
            path: 'serviceProductList',
            name: '服务产品上架',
            component: () => import(/* webpackChunkName: "about" */ '@/views/pageContent/serviceProduct/serviceProductList.vue')
          },
          {
            path: 'serviceProductPreview',
            name: '服务产品上架预览',
            component: () => import(/* webpackChunkName: "about" */ '@/views/pageContent/serviceProduct/serviceProductPreview.vue')
          },
          {
            path: 'couponExchange',
            name: '服务券兑付',
            component: () => import(/* webpackChunkName: "about" */ '@/views/pageContent/couponExchange/index.vue')
          },
          {
            path: 'couponExchangeApply',
            name: '服务商申请兑付',
            component: () => import(/* webpackChunkName: "about" */ '@/views/pageContent/couponExchange/couponExchangeApply.vue')
          },
          {
            path: 'myColletion',
            name: '我的收藏',
            component: () => import(/* webpackChunkName: "about" */ '@/views/pageContent/myColletion/index.vue')
          },
          {
            path: 'requirementManage',
            name: '我的需求管理',
            component: () => import(/* webpackChunkName: "about" */ '@/views/pageContent/requirementManage/index.vue')
          },
          {
            path: 'creatRequirement',
            name: '发布需求',
            component: () => import(/* webpackChunkName: "about" */ '@/views/pageContent/requirementManage/creatRequirement.vue')
          },
          {
            path: 'requirementDetail',
            name: '需求详情',
            component: () => import(/* webpackChunkName: "about" */ '@/views/pageContent/requirementManage/requirementDetail.vue')
          },
        ]
      },
    ]
  },
  // {
  //   path: '/',
  //   redirect: '/index'
  // },
  // {
  //   path: '*',
  //   redirect: '/index'
  // },
  {
    path: '/login',
    name: '登录',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '@/views/pageContent/personalCenter/login.vue')
  },
  {
    path: '/register',
    name: '注册',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '@/views/pageContent/personalCenter/register.vue')
  },
  {
    path: '/transfer',
    name: '跳转小程序',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '@/views/pageContent/personalCenter/transfer.vue')
  }
]

const router = new VueRouter({
   mode: 'history',
   // base: process.env.BASE_URL,
   routes
 })
// const LOGIN_PAGE_PATH = '/login';
// const REGISTER_PAGE_PATH = '/register';
// const TRANSFER_PAGE_PATH = '/transfer';
// const HOME_PAGE_PATH = '/index';
// router.beforeEach((to, from, next) => {
//   NProgress.start()
//   const token = getToken()
//   if (!token || token === 'undefined') {
//     if (to.path !== LOGIN_PAGE_PATH) {
//       if (to.path === REGISTER_PAGE_PATH|| to.path === TRANSFER_PAGE_PATH) {
//         next()
//       } else {
//         next({
//           path: LOGIN_PAGE_PATH
//         })
//       }
//     } else {
//       next()
//     }
//   } else {
//     if (to.path === LOGIN_PAGE_PATH || to.path === REGISTER_PAGE_PATH) {
//       next({
//         path: HOME_PAGE_PATH
//       })
//     } else {
//      next()
//     }
//   }
// })
// router.afterEach(to => {
//   setTitle(to);
//   NProgress.done()
//   window.scrollTo(0, 0)
// })
export default router
